<?php

namespace Admin\Controller;
use Think\Controller;

class FeedbackController extends Controller{

    /*
    列表
    */

    public function lists(){

        $this->isAjaxLogin();//检查是否登录

        $page = I('post.page/d');//当前页数
        $page_size = I('post.page_size/d');

        $model=M('feedback');

        $count = $model->count();
        $total =  ceil($count / $page_size);
        $limitStart = ($page-1) * $page_size;
        
        $result=$model->order("id desc")->limit($limitStart,$page_size)->select();

        if($result !== false){

            $data['page']['total_page'] = $total;
            $data['list'] = $result;
            

            $ajaxReturn['code'] = 1;
            $ajaxReturn['msg'] = "SUCCESS";
            $ajaxReturn['data'] = $data;
        }else{

            $ajaxReturn['code'] = 2;
            $ajaxReturn['msg'] = "数据查询失败！";
        }
        $this->ajaxReturn($ajaxReturn);
    }

    /*
    展示所属类型
    */

     public function type_lists(){
        $this->isAjaxLogin();//检查是否登录


        $model=M('advise_type');

        $result=$model->field('type_name')->select();

         if($result !== false){

            $ajaxReturn['code'] = 1;
            $ajaxReturn['msg'] = "SUCCESS";
            $ajaxReturn['data'] = $result;
        }else{

            $ajaxReturn['code'] = 2;
            $ajaxReturn['msg'] = "数据查询失败！";
        }
        $this->ajaxReturn($ajaxReturn);
    }

    /*
    新增建议
    */
    public function add(){

        $this->isAjaxLogin();//检查是否登录

        $model=D('feedback');

        $type_name=I('post.type_name');//建议
        $content=I('post.content');//建议内容
        $name=I('post.name');//建议人姓名	
        $phone=I('post.phone');//联系方式
        $weixin=I('post.weixin');//微信号
        $qq=I('post.qq');//qq号码

        $data['type_name']   = $type_name;
        $data['content']   = $content;
        $data['name'] = $name;
        $data['phone'] = $phone;
        $data['weixin'] = $weixin;
        $data['qq']=$qq;
        if($model->add($data)){
            $ajaxReturn['code'] = 1;
            $ajaxReturn['msg'] = "SUCCESS";
        }else{
            $ajaxReturn['code'] = 2;
            $ajaxReturn['msg'] =  $model->getError();
        }
        
        $this->ajaxReturn($ajaxReturn);
    }

    /*
    详情
    */
    public  function infos(){
        $this->isAjaxLogin();

        $id = I('post.id/d');

        $Model = M('feedback');

        $result = $Model->where([
                'id'=>$id,
            ])->find();

        if($result){

            $ajaxReturn['code'] = 1;
            $ajaxReturn['msg'] = "SUCCESS";
            $ajaxReturn['data'] = $result;

        }else{

            $ajaxReturn['code'] = 2;
            $ajaxReturn['msg'] = "查询数据失败！";
        }

        $this->ajaxReturn($ajaxReturn);
    }
}